<html>
<head>
	<meta charset="UTF-8">
	<link href="./static/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
	<link href="./static/assets/global/css/components.css" rel="stylesheet" type="text/css"/>
	<link href="./static/assets/admin/pages/css/login.css" rel="stylesheet" type="text/css"/>
	<script src="./static/assets/global/plugins/jquery-1.11.0.min.js" type="text/javascript"></script>
	<script src="./js/common.js" type="text/javascript"></script>
</head>

<body>
<div class="content">
	<h3 class="form-title">订单列表</h3>
	<div class="table-responsive">
		<table class="table">
			<thead>
			<tr>
				<th>订单编号</th>
				<th>用户编号</th>
				<th>活动编号</th>
				<th>商品编号</th>
				<th>商品名称</th>
				<th>秒杀价格</th>
				<th>购买数量</th>
				<th>订单总金额</th>
				<th>状态</th>
				<th>创建时间</th>
			</tr>
			</thead>
			<tbody id="container">
			</tbody>
		</table>
	</div>
</div>

</body>

<script>
	// 定义全局活动数组信息
	var g_activityList = [];

	jQuery(document).ready(function () {
		var userId = getParameterByName("userId");
		$.ajax({
			type:"GET",
			headers:{
				"access-token": get(common_localstorage_key)
			},
			url:"http://"+g_host+"/order/getSeckillOrderByUserId?userId=" + userId,
			xhrFields: {withCredentials: true},
			success:function (data) {
				if (data.code == 1001) {
					g_activityList = data.data;
					reloadDom();
				}else if (data.code == 2012){
					alert("请登录后操作");
					window.location.href = "login.html";
				}
				else {
					alert("获取活动信息失败");
				}
			},
			error:function (data) {
				alert("获取活动信息失败");
			}
		})
	})

	function reloadDom() {
		for (var i = 0; i < g_activityList.length; i ++){
			var itemVO = g_activityList[i];
			var dom = "<tr id='goodsDetail"+ itemVO.id +"'>" +
					"<td>"+ itemVO.id +"</td>" +
					"<td>"+ itemVO.userId +"</td>" +
					"<td>"+ itemVO.activityId +"</td>" +
					"<td>"+ itemVO.goodsId +"</td>" +
					"<td>"+ itemVO.goodsName +"</td>" +
					"<td>"+ itemVO.activityPrice +"</td>" +
					"<td>"+ itemVO.quantity +"</td>" +
					"<td>"+ itemVO.orderPrice +"</td>" +
					"<td>"+ getStatus(itemVO.status) +"</td>" +
					"<td>"+ itemVO.createTime +"</td>" +
					"</tr>";
			$("#container").append($(dom));
		}
	}

	function getStatus(status){
		if (status == 1){
			return "待支付";
		}else if (status == 2){
			return "已支付";
		}else if (status == 0){
			return "已取消";
		}else if (status == -1){
			return "已删除"
		}
	}
</script>
</html>